<!-- //浙里办申请 v2 -->
<template>
  <div class="applyFor">
    <ul>
      <li v-for="item in applyInfo">
        <div class="subTitle">{{ item.title }}</div>
        <div class="son">
          <div v-for="son in item.son" style="width: 47%; display: flex; padding: 0 10px 30px 10px" @click="handleTo(son)">
            <div style="padding-right: 8px; line-height: 36px">
              <img :src="son.icon" alt="" style="width: 90%" />
            </div>
            <div style="line-height: 36px; position: relative">
              {{ son.name }}
              <span v-if="son.ative" style="width: 5px; height: 5px; background-color: red; border-radius: 50%; display: inline-block; position: absolute; top: 6px; right: -10px"></span>
            </div>
          </div>
        </div>
        <div style="background-color: #f6f6f6; height: 14px; margin-top: 4px"></div>
      </li>
    </ul>
  </div>
</template>

<style lang="scss" scoped>
.applyFor {
  width: 100%;
  height: 100vh;
  color: black;
  background: #fff;
  padding: 6px 10px;
  overflow: auto;
  .subTitle {
    height: 40px;
    line-height: 40px;
    font-size: 18px;
    font-weight: bold;
  }
  .son {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    height: auto;
    padding: 20px 0 0 0;
    font-size: 15px;
  }
}
</style>

<script>
import { addDate, GSA_Search1, GSA_Add } from '@/common/commonApi'
import { getTaskName } from '@/utils/node_guid.js'
import { useSend, useSend2 } from './send'
import { farmerHouseProjectPush } from '@/utils/api.js'
export default {
  data() {
    let title = ''
    return {
      // 申请人信息
      baseurlid: window.g.OSSPriviewId,
      applyInfo: [
        {
          title: '施工单位',
          son: [
            {
              name: '选择施工单位',
              icon: 'https://nfzjszlb.jst.zj.gov.cn/tyzcpt/serverfile/zheliban/icon/ZLJ/SGQT/1.png',
              ative: false
            },
            {
              name: '更换施工单位',
              icon: 'https://nfzjszlb.jst.zj.gov.cn/tyzcpt/serverfile/zheliban/icon/ZLJ/SGQT/2.png',
              ative: false
            }
          ]
        },
        {
          title: '合同签订',
          son: [
            {
              name: '合同签订',
              icon: 'https://nfzjszlb.jst.zj.gov.cn/tyzcpt/serverfile/zheliban/icon/ZLJ/SGQT/3.png',
              ative: false
            }
          ]
        },
        {
          title: '施工备案',
          son: [
            {
              name: '施工备案申请',
              icon: 'https://nfzjszlb.jst.zj.gov.cn/tyzcpt/serverfile/zheliban/icon/ZLJ/SGQT/4.png',
              ative: false
            },
            {
              name: '施工备案变更',
              icon: 'https://nfzjszlb.jst.zj.gov.cn/tyzcpt/serverfile/zheliban/icon/ZLJ/SGQT/5.png',
              ative: false
            },
            {
              name: '施工备案延期',
              icon: 'https://nfzjszlb.jst.zj.gov.cn/tyzcpt/serverfile/zheliban/icon/ZLJ/SGQT/6.png',
              ative: false
            }
          ]
        },
        {
          title: '四到场',
          son: [
            {
              name: '预约定位放样',
              icon: 'https://nfzjszlb.jst.zj.gov.cn/tyzcpt/serverfile/zheliban/icon/ZLJ/SGQT/7.png',
              ative: false
            },
            {
              name: '预约基槽验线',
              icon: 'https://nfzjszlb.jst.zj.gov.cn/tyzcpt/serverfile/zheliban/icon/ZLJ/SGQT/8.png',
              ative: false
            },
            {
              name: '预约一层立模',
              icon: 'https://nfzjszlb.jst.zj.gov.cn/tyzcpt/serverfile/zheliban/icon/ZLJ/SGQT/9.png',
              ative: false
            },
            {
              name: '预约竣工验收',
              icon: 'https://nfzjszlb.jst.zj.gov.cn/tyzcpt/serverfile/zheliban/icon/ZLJ/SGQT/10.png',
              ative: false
            }
          ]
        }
        // {
        //   title: '地名牌',
        //   son: [
        //     {
        //       name: '申请地名牌',
        //       icon: 'https://nfzjszlb.jst.zj.gov.cn/tyzcpt/serverfile/zheliban/icon/ZLJ/SGQT/11.png',
        //       ative: false
        //     }
        //   ]
        // },
        // {
        //   title: '施工日志',
        //   son: [
        //     {
        //       name: '添加施工日志',
        //       icon: 'https://nfzjszlb.jst.zj.gov.cn/tyzcpt/serverfile/zheliban/icon/ZLJ/SGQT/12.png',
        //       ative: false
        //     }
        //   ]
        // }
      ],
      rowdata: {},
      GJDATA: [],
      isQian: false,
      qianhetong: []
    }
  },
  methods: {
    async handleTo(item) {
      if (!item.ative) {
        this.$confirm({
          title: '提示',
          message: '还未到此环节，请选择其他环节',
          btn: {
            okText: '确定',
            cancelText: '取消'
          }
        })
          .then(() => {
            // do something
          })
          .catch(() => {
            console.log('no')
          })
        return false
      }
      // 先判断现在可以点击哪些按钮
      if (item.name === '选择施工单位') {
        //判断是否选择过工匠
        if (this.GJDATA.length > 0) {
          // 提示是否更换工匠
          this.$confirm({
            title: '提示',
            message: '已经选择了工匠,是否更换工匠',
            btn: {
              okText: '确定',
              cancelText: '取消'
            }
          })
            .then(() => {
              this.GJDATA.push({
                PKID: this.rowdata.PKID
              })
              window.sessionStorage.setItem('applyFor', JSON.stringify(this.GJDATA[0]))
              window.sessionStorage.setItem('isadd', 1)
              this.$router.push({
                path: '/selectCompany'
              })
            })
            .catch(() => {
              console.log('no')
            })
        } else {
          window.sessionStorage.setItem('isadd', 2)
          window.sessionStorage.setItem('applyFor', JSON.stringify(this.rowdata))
          this.$router.push({
            path: '/selectCompany'
          })
        }
      } else if (item.name === '更换施工单位') {
        if (this.GJDATA.length > 0) {
          this.GJDATA.push({
            PKID: this.rowdata.PKID
          })
          window.sessionStorage.setItem('applyFor', JSON.stringify(this.GJDATA[0]))
          window.sessionStorage.setItem('isadd', 1)
          this.$router.push({
            path: '/selectCompany'
          })
        } else {
          this.$confirm({
            title: '提示',
            message: '还未选择工匠,请选择工匠',
            btn: {
              okText: '确定',
              cancelText: '取消'
            }
          })
            .then(() => {
              this.$router.push({
                path: '/selectCompany'
              })
            })
            .catch()
        }
      } else if (item.name === '合同签订') {
        //要选择了工匠才能签订合同
        if (this.GJDATA.length > 0) {
          //判断是企业还是工匠
          //根据当前的角色确认合同更新对应的字段  农户、代办人：HTBHQDZT   工匠：HTQDZT  项目负责人：F_JZQYXMFZR 施工负责人：F_JZQYSGFZR
          if (
            (this.rowdata.OPTYPE == '59' && (!this.rowdata.HTBHQDZT || !this.rowdata.HTQDZT)) ||
            (this.rowdata.OPTYPE == '60' && (!this.rowdata.HTBHQDZT || !this.rowdata.F_JZQYXMFZR || !this.rowdata.F_JZQYSGFZR))
          ) {
            this.$router.push({
              path: '/ConstructionContract',
              query: { data: JSON.stringify(this.rowdata) }
            })
          } else {
            this.$confirm({
              title: '提示',
              message: '已完成签合同,请发起定位放样',
              btn: {
                okText: '确定',
                cancelText: '取消'
              }
            })
              .then(() => {})
              .catch()
          }
        } else {
          this.$confirm({
            title: '提示',
            message: '还未选择工匠,请选择工匠',
            btn: {
              okText: '确定',
              cancelText: '取消'
            }
          })
            .then(() => {
              this.$router.push({
                path: '/selectCompany'
              })
            })
            .catch()
        }
      } else if (
        item.name === '施工备案申请' &&
        ((this.rowdata.OPTYPE == '59' && this.rowdata.HTBHQDZT && this.rowdata.HTQDZT) ||
          (this.rowdata.OPTYPE == '60' && this.rowdata.HTBHQDZT && this.rowdata.F_JZQYXMFZR && this.rowdata.F_JZQYSGFZR))
      ) {
        window.sessionStorage.setItem('fileData', JSON.stringify(this.rowdata))
        window.sessionStorage.setItem('applyFor', JSON.stringify(this.GJDATA[0]))
        window.localStorage.setItem('newData', 1)
        this.$router.push({
          path: '/fileData'
        })
      } else if (item.name === '施工备案变更') {
        window.sessionStorage.setItem('fileData', JSON.stringify(this.rowdata))
        window.sessionStorage.setItem('applyFor', JSON.stringify(this.GJDATA[0]))
        window.sessionStorage.setItem('RUNTYPE', '2')
        this.$router.push({
          path: '/biangeng'
        })
      } else if (
        item.name === '施工备案延期' &&
        ((this.rowdata.OPTYPE == '59' && this.rowdata.HTBHQDZT && this.rowdata.HTQDZT) ||
          (this.rowdata.OPTYPE == '60' && this.rowdata.HTBHQDZT && this.rowdata.F_JZQYXMFZR && this.rowdata.F_JZQYSGFZR))
      ) {
      } else if (item.name === '预约定位放样' || item.name === '预约基槽验线' || item.name === '预约一层立模' || item.name === '预约竣工验收') {
        if (
          (this.rowdata.OPTYPE == '59' && this.rowdata.HTBHQDZT && this.rowdata.HTQDZT) ||
          (this.rowdata.OPTYPE == '60' && this.rowdata.HTBHQDZT && this.rowdata.F_JZQYXMFZR && this.rowdata.F_JZQYSGFZR)
        ) {
          let pranmes = {
            serviceId: 'getStageInfo',
            buildIdCard: this.rowdata.ID_CARD
          }
          const res = await farmerHouseProjectPush(pranmes)
          let dd = JSON.parse(res.data.data)
          // if (dd.data?.drawingInfo.length > 0 || dd.data?.stageInfo.length > 0 || this.rowdata.TSZT) {
          this.$confirm({
            title: '提示',
            message: '是否发起' + item.name,
            btn: {
              okText: '确定',
              cancelText: '取消'
            }
          }).then(() => {
            //发送
            useSend2(this.rowdata, this.callBack, this.errorBack)
          })
        } else {
          this.$toast.fail('请先确认合同')
        }
        // } else {
        //   this.$toast.fail('图审未通过')
        // }
        //需要先判断是否签订过合同  如果是工匠 需要判断线上合同和线下合同
        //是否签过线下合同·
        // let data = [
        //   { field: 'TO_ROW_GUID', value: this.rowdata.ROW_GUID, operator: '=' },
        //   { field: 'GROUPGUID', value: '2774cbb5-1854-4a0a-afaf-bee2e8f83cab' }
        // ]
        // const res = await GSA_Search('6b39e223-de8a-43b3-a846-65307cc75e69', data)
        // let xianxia = res.Data
        // if (this.GJDATA[0].TYPE == '59') {
        //   let data = [{ field: 'TO_ROW_GUID', value: this.rowdata.ROW_GUID, operator: '=' }]
        //   const res = await GSA_Search('7c0bdd5c-c465-4705-b774-6c5e1455c976', data)
        //   this.qianhetong = res.Data
        // }

        // if (this.GJDATA[0].TYPE == '59' ? this.qianhetong.length == 0 && xianxia.length == 0 : xianxia.length == 0) {
        //   this.$confirm({
        //     title: '提示',
        //     message: '还未签合同,请先签合同',
        //     btn: {
        //       okText: '确定',
        //       cancelText: '取消'
        //     }
        //   })
        //     .then(() => {})
        //     .catch()
        // } else {

        // }
      } else if (item.name === '申请地名牌') {
        this.$router.push({
          path: '/HouseBrand'
        })
      } else if (item.name === '添加施工日志') {
      }
    },
    callBack() {
      this.$toast.success('发送成功')
      this.$router.push({
        path: './zljindex'
      })
    },
    errorBack() {
      this.$toast.fail('失败')
    },
    //判断是否选择了工匠
    async handleSelectgj() {
      let data = [{ field: 'TO_ROW_GUID', value: this.rowdata.ROW_GUID }]
      const res = await GSA_Search1('7c3a7582-4a27-4fab-a5b3-b2da427cb989', data)
      this.GJDATA = res.Data
      console.log(this.WF_GUID == '{128070D0-52B2-4E92-ADD8-96D6F9044C60}' , this.NODE_GUID != '{E349B5CD-E963-4A17-ABE4-258EF79C55F2}')
      if (this.rowdata.NODE_GUID == '{FEF0E7B0-F048-42E0-998E-06387B0D03DB}' && this.GJDATA.length == 0) {
        this.applyInfo[0].son[0].ative = true
      } else if (this.rowdata.NODE_GUID == '{FEF0E7B0-F048-42E0-998E-06387B0D03DB}' && this.GJDATA.length > 0 && !this.isQian) {
        this.applyInfo[1].son[0].ative = true
      } else if (this.rowdata.NODE_GUID == '{FEF0E7B0-F048-42E0-998E-06387B0D03DB}' && this.GJDATA.length > 0 && this.isQian) {
        this.applyInfo[2].son[0].ative = true
        this.applyInfo[2].son[1].ative = true
        this.applyInfo[0].son[1].ative = true
      } else if (this.rowdata.WF_GUID == '{128070D0-52B2-4E92-ADD8-96D6F9044C60}' && this.rowdata.NODE_GUID != '{E349B5CD-E963-4A17-ABE4-258EF79C55F2}') {
        this.applyInfo[2].son[1].ative = true
        this.applyInfo[2].son[2].ative = true
        this.applyInfo[0].son[1].ative = true
      } else if (this.rowdata.NODE_GUID == '{E349B5CD-E963-4A17-ABE4-258EF79C55F2}') {
        this.applyInfo[2].son[1].ative = true
        this.applyInfo[2].son[2].ative = true
        this.applyInfo[0].son[1].ative = true
        this.applyInfo[3].son[0].ative = true
      } else if (this.rowdata.NODE_GUID == '{F81FCB82-7196-4E94-BFF5-159E1CEBEFF8}') {
        this.applyInfo[2].son[1].ative = true
        this.applyInfo[0].son[1].ative = true
        this.applyInfo[2].son[2].ative = true
        this.applyInfo[3].son[1].ative = true
      } else if (this.rowdata.NODE_GUID == '{10BAEA52-EDDE-48C7-97AD-C211D272010E}') {
        this.applyInfo[2].son[1].ative = true
        this.applyInfo[2].son[2].ative = true
        this.applyInfo[0].son[1].ative = true
        this.applyInfo[3].son[2].ative = true
      } else if (this.rowdata.NODE_GUID == '{C89D1E12-1303-482F-BB9E-45457905C759}') {
        this.applyInfo[2].son[1].ative = true
        this.applyInfo[2].son[2].ative = true
        this.applyInfo[0].son[1].ative = true
        this.applyInfo[3].son[3].ative = true
      }
    }
  },
  mounted() {
    this.rowdata = JSON.parse(this.$route.query.data)
    if (
      (this.rowdata.OPTYPE == '59' && (!this.rowdata.HTBHQDZT || !this.rowdata.HTQDZT)) ||
      (this.rowdata.OPTYPE == '60' && (!this.rowdata.HTBHQDZT || !this.rowdata.F_JZQYXMFZR || !this.rowdata.F_JZQYSGFZR))
    ) {
      //标识还没签完合同
      this.isQian = false
    } else if (
      (this.rowdata.OPTYPE == '59' && this.rowdata.HTBHQDZT && this.rowdata.HTQDZT) ||
      (this.rowdata.OPTYPE == '60' && this.rowdata.HTBHQDZT && this.rowdata.F_JZQYXMFZR && this.rowdata.F_JZQYSGFZR)
    ) {
      this.isQian = true
    }
    //标识已经签完合同
    let bolloe =
      (this.rowdata.OPTYPE == '59' && this.rowdata.HTBHQDZT && this.rowdata.HTQDZT) || (this.rowdata.OPTYPE == '60' && this.rowdata.HTBHQDZT && this.rowdata.F_JZQYXMFZR && this.rowdata.F_JZQYSGFZR)
    this.title = getTaskName(this.rowdata.NODE_GUID, bolloe)
    this.handleSelectgj()
    //改变小红点
    // this.applyInfo.forEach((item) => {
    //   item.son.forEach((element) => {
    //     this.title.forEach((it) => {
    //       if (element.name == it) {
    //         element.ative = true
    //       }
    //       if (it == '选择施工单位&&合同签订') {
    //         this.applyInfo[0].son[0].ative = true
    //         // this.applyInfo[0].son[1].ative = true
    //         this.applyInfo[1].son[0].ative = true
    //       }
    //     })
    //   })
    // })

    // //施工备案需要判断WF_GUID
    // if (this.rowdata.WF_GUID == '{128070D0-52B2-4E92-ADD8-96D6F9044C60}') {
    //   //施工备案申请
    //   this.applyInfo[2].son[0].ative = true
    // } else if (this.rowdata.WF_GUID == '{C80F01CD-2180-416B-A232-ED0218B72ECE}') {
    //   //施工备案变更流程
    //   this.applyInfo[2].son[1].ative = true
    // } else if (this.rowdata.WF_GUID == '{8FF5FA40-5AEC-47C2-B432-A53BDE9967D1}') {
    //   //施施工备案延期流程
    //   this.applyInfo[2].son[2].ative = true
    // } else if (this.rowdata.NODE_GUID == '{B8C0E603-AB3B-4FA6-BC92-21D4F393CC28}') {
    //   this.applyInfo[0].son[0].ative = true
    //   // this.applyInfo[0].son[1].ative = true
    //   this.applyInfo[1].son[0].ative = true
    //   this.applyInfo[2].son[0].ative = true
    //   this.applyInfo[3].son[0].ative = true
    // }
    // console.log(window.localStorage.getItem('isGJM') == "false",'kkkk')
    if (window.localStorage.getItem('isGJM') == 'false') {
      debugger
      this.applyInfo = [
        {
          title: '合同签订',
          son: [
            {
              name: '合同签订',
              icon: 'https://nfzjszlb.jst.zj.gov.cn/tyzcpt/serverfile/zheliban/icon/ZLJ/SGQT/3.png',
              ative: true
            }
          ]
        }
      ]
    }
  }
}
</script>
